package books.ThinkingInJava.src.Chapter18;

import books.ThinkingInJava.src.Tools.Output;

import java.nio.ByteBuffer;

/**
 * @author bloodcolding
 * @since 12/28/2018 8:03 PM
 */
public class TextBuffer {
    public static void main(String[] args) {
        ByteBuffer buff = ByteBuffer.allocate(2048);
        buff.asCharBuffer().put("1111");
        char c;
        buff.flip(); //把写切换成读
        while ((c = buff.getChar()) != 0) {
            System.out.print(c);
        }

        System.out.println();


        buff.rewind(); //重新从头开始读
        buff.clear();
        buff.asDoubleBuffer().put(1.111d);
        double d;
        buff.flip(); //把写切换成读
        while ((d = buff.getDouble()) != 0) {
            System.out.println(d);
        }

        buff.clear();
        int i = 0;
        while (i++ < buff.limit()) {
            if (buff.get() != 0) {
                Output.println("nozero");
            }
        }
    }
}

